/*
 * Copyright 2011 Angel Sanadinov
 *
 * This file is part of VBox WMI.
 *
 * VBox WMI is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * VBox WMI is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with VBox WMI.  If not, see <http://www.gnu.org/licenses/>.
 */

package Beans.Requests.MediumManagement;

import Utilities.Functions;
import Utilities.PermissionsConstants;

/**
 * Instances of this class are used by the user interface when a request to
 * merge hard disks is sent to the media management service.
 *
 * @author Angel Sanadinov
 */
public class MergeDisksRequest extends MediumManagementRequest
{
    private String targetId; //the id of the target disk

    /**
     * No-argument constructor. <br><br>
     * All fields are set to their invalid values.
     */
    public MergeDisksRequest()
    {
        setRequestedAction(PermissionsConstants.ACTION_MEDIUM_MERGE);
        this.targetId = null;
    }

    /**
     * Constructs a "merge disk" request with the specified data.
     *
     * @param requestorId the id of the user that made the request
     * @param serverId the id of the server on which the disk resides
     * @param mediumId the id of the source disk
     * @param targetId the id of the target disk
     */
    public MergeDisksRequest(int requestorId, int serverId, String mediumId, String targetId)
    {
        setRequestedAction(PermissionsConstants.ACTION_MEDIUM_MERGE);
        setRequestorId(requestorId);
        setServerId(serverId);
        setMediumId(mediumId);
        this.targetId = targetId;
    }

    /**
     * Retrieves the id of the target disk.
     *
     * @return the target disk id
     */
    public String getTargetId()
    {
        return targetId;
    }

    /**
     * Sets the id of the target disk.
     *
     * @param targetId the target disk id
     */
    public void setTargetId(String targetId)
    {
        this.targetId = targetId;
    }

    @Override
    public boolean isValid()
    {
        if(super.isValid() && isMediumIdValid() && Functions.isUUIDValid(targetId)
                && !getMediumId().equalsIgnoreCase(targetId))
        {
            return true;
        }
        else
            return false;
    }

    /**
     * Returns a textual representation of the object. <br>
     *
     * It is in the form: "ClassName: (mediumId,targetId)".
     *
     * @return the object represented as a String
     */
    @Override
    public String toString()
    {
        return MergeDisksRequest.class.getSimpleName() + ": (" + getMediumId() + "," + targetId + ")";
    }
}
